﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankSimulation
{
    internal class CreditAccount:Account
    {
        //----------字段----------
        double creditBalance;

        //----------属性----------


        //----------构造方法----------
        public CreditAccount(string id, string pwd, double money, double creditBalance) : base(id, pwd, money)
        {
            this.creditBalance = creditBalance;
            //新的钱数等于信用额度+原来的钱数
            this.Money = creditBalance + this.Money;
            this.AccountType = "信用账户";
        }   
        public CreditAccount(string id, string pwd, double money) : base(id,pwd,money)
        {
            this.creditBalance = 0;
            this.AccountType = "储蓄账户";

        }
            

        //----------属性----------
        public double CreditBalance
        {
            get { return creditBalance; }
            set { creditBalance = value; }
        }

        //----------方法----------
        //因为有信用额度，所以取钱方法不同，先简单起见，钱数等于现金+信用额度
        /*public override bool WithdrawMoney(double money)
        {
            if (this.Money + creditBalance < money)
            {
                MessageBox.Show("取钱失败，不能取出超过余额和信用额度的钱");
                return false;
            }
            else
            {
                MessageBox.Show($"取钱成功！本次取出{money}");
                //如果余额不够，先从信用额度里面取
                if (this.Money < money)
                {
                    creditBalance -= (money - this.Money);
                    this.Money = 0;
                }
                else
                {
                    this.Money -= money;
                }
                return true;
            }
        }*/
        //更改信用额度
        public bool ChangeCreditBalance(double credit)
        {
            if(credit > 0)
            {
                this.Money = this.Money + credit - this.creditBalance;
                this.creditBalance = credit;
                return true;
            }
            else
            {
                MessageBox.Show("信用额度不能为负数");
                return false;
            }

        }
    }
}
